package com.reden.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {

    private static String formatYear = "yyyy"; //年
    private static String formatMouth = "MM"; //月
    private static String formatDay = "dd"; //日
    private static String formatHour = "HH"; //时
    private static String formatMinute = "mm"; //分
    private static String formatSecond = "ss"; //秒
    private static String formatMillis = "SSS"; //毫秒
    private static String formatDate = "yyyy-MM-dd"; //年-月-日
    private static String formatTime = "HH:mm:ss"; //时:分:秒
    private static String formatDateTime = "yyyy-MM-dd HH:mm:ss"; //年-月-日 时:分:秒

    // 获取日期
    public static String getDate() {return getDate(new Date(), formatDate);}
    public static String getDate(Date date) {return getDate(new Date(), formatDate);}
    public static String getDate(String format) {return getDate(new Date(), format);}
    public static String getDate(Date date, String format) {return new SimpleDateFormat(format).format(new Date());}

    // 获取时间
    public static String getTime() {return getTime(new Date(), formatTime);}
    public static String getTime(Date date) {return getTime(new Date(), formatTime);}
    public static String getTime(String format) {return getTime(new Date(), format);}
    public static String getTime(Date date, String format) {return new SimpleDateFormat(format).format(new Date());}

    // 获取日期+时间
    public static String getDateTime() {return getDateTime(new Date(), formatDateTime);}
    public static String getDateTime(Date date) {return getDateTime(new Date(), formatDateTime);}
    public static String getDateTime(String format) {return getDateTime(new Date(), format);}
    public static String getDateTime(Date date, String format) {return new SimpleDateFormat(format).format(new Date());}

    // 获取年
    public static String getYear() {return getYear(new Date());}
    public static String getYear(Date date) {return new SimpleDateFormat(formatYear).format(new Date());}

    // 获取月
    public static String getMonth() {return getMonth(new Date());}
    public static String getMonth(Date date) {return new SimpleDateFormat(formatMouth).format(new Date());}

    // 获取日
    public static String getDay() {return getDay(new Date());}
    public static String getDay(Date date) {return new SimpleDateFormat(formatDay).format(new Date());}

    // 获取时
    public static String getHour() {return getHour(new Date());}
    public static String getHour(Date date) {return new SimpleDateFormat(formatHour).format(new Date());}

    // 获取分
    public static String getMinute() {return getMinute(new Date());}
    public static String getMinute(Date date) {return new SimpleDateFormat(formatMinute).format(new Date());}

    // 获取秒
    public static String getSecond() {return getSecond(new Date());}
    public static String getSecond(Date date) {return new SimpleDateFormat(formatSecond).format(new Date());}

    // 获取毫秒
    public static String getMillis() {return getMillis(new Date());}
    public static String getMillis(Date date) {return new SimpleDateFormat(formatMillis).format(new Date());}

    // 获取时间戳
    public static String getTimeStamp() {return getTimeStamp(new Date());}
    public static String getTimeStamp(Date date) {return getTimeStampSecond(new Date());}

    // 获取时间戳(秒)
    public static String getTimeStampSecond() {return getTimeStampSecond(new Date());}
    public static String getTimeStampSecond(Date date) {return String.valueOf(new Date().getTime() / 1000);}

    // 获取时间戳(毫秒)
    public static String getTimeStampMillis() {return getTimeStampMillis(new Date());}
    public static String getTimeStampMillis(Date date) {return String.valueOf(new Date().getTime());}

    // 将字符串转换为时间
    public static Date getDateByString(String string) throws ParseException {return getDateByString(formatDateTime, string);}
    public static Date getDateByString(String string, String format) throws ParseException {return new SimpleDateFormat(format).parse(string);}
}
